package sunwin.yoms.service.system;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.comm.YomsPage;
import sunwin.yoms.dao.AdminLoginLogDao;
import sunwin.yoms.domain.system.AdminLoginLogDomain;

import java.util.List;

/**
 * Created by watson on 2015/10/30.
 */
@Service
public class AdminLoginLogService {
    @Autowired
    private AdminLoginLogDao adminLoginLogDao;

    /**
     * 查询登陆日志
     */
    public List<AdminLoginLogDomain> getAdminLoginLog(AdminLoginLogDomain adminLoginLogDomain,YomsPage yomsPage) throws YomsException {
        com.github.pagehelper.Page total = PageHelper.startPage(yomsPage.getPageIndex(), yomsPage.getPageSize(), true);
        List<AdminLoginLogDomain> domains = adminLoginLogDao.getDomainCollection(adminLoginLogDomain);
        yomsPage.setPageCount(total.getTotal() % yomsPage.getPageSize() == 0 ? total.getTotal() / yomsPage.getPageSize() : total.getTotal() / yomsPage.getPageSize() + 1);
        if (domains.size() <= 0) {
            throw new YomsException("没有查询到日志");
        } else {
            return domains;
        }
    }

    /**
     *增加日志
     */
    public void addAdminLoginLog(AdminLoginLogDomain adminLoginLogDomain)throws YomsException{
        adminLoginLogDao.addDomain(adminLoginLogDomain);
    }
}
